import time
from selenium import webdriver
from lxml import etree

def write_local_file(filename,text):
    with open(filename,"w",encoding="utf-8") as file:
        file.write(text)
        file.close()

def fetch_website(url):
    driver = webdriver.Firefox()
    driver.get(url)
    return driver

def qianfeng_login(url):
    driver = fetch_website(url)

    # 进入登录界面
    time.sleep(1)
    driver.find_element_by_name("Account").send_keys("421083199405194730")
    driver.find_element_by_name("PassWord").send_keys("194730")
    driver.find_element_by_xpath('//form/fieldset/div/button').click()

    # response = driver.page_source
    # write_local_file("email_login.html",response)

    # 进入首页界面,点击测评
    time.sleep(1)
    driver.find_element_by_xpath('//ul[@class="submenu"]/li[5]').click()
    # 进入测评界面
    time.sleep(1)
    driver.find_element_by_xpath('//tbody/tr[1]/td[last()]').click()

    time.sleep(10)
    driver.quit()

# def qianfeng_login_val(driver):
#     # html_doc = qianfeng_login(url)
#     # html_tree = etree.HTML(html_doc)
#     next_driver =  qianfeng_login(url)



if __name__ == "__main__":
    url = "http://stu.1000phone.net/student.php/Public/login"
    qianfeng_login(url)